﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using Emgu.CV.UI;
using GeometryProcessing;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace CCD
{
    public partial class ProcessUI : Form
    {
        public ProcessUI(string modelname)
        {
            InitializeComponent();
            this.ModelName = modelname;
            GetBlockInfo();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //string imgStr = "pic\\test\\C0_001.bmp";
            //Image<Rgb, Byte> imgProc = new Image<Rgb, byte>(imgStr);
            //ProcessConsole process = new ProcessConsole(
            //    imgProc,
            //    Paths.GetModelPath(listBox1.SelectedItem.ToString())
            //    );
            //process.Show();
            //process.TestBlock(Paths.GetMaskFilename(listBox1.SelectedItem.ToString(), listBox2.SelectedItem.ToString()));
        }

        private void GetBlockInfo()
        {
            DirectoryInfo di = new DirectoryInfo(Paths.ModelPath + "\\" + this.ModelName + "\\blocks");
            try
            {
                //Clear the box first
                checkedListBox1.BeginUpdate();
                checkedListBox1.Items.Clear();
                checkedListBox1.EndUpdate();

                // Determine whether the directory exists.
                if (di.Exists)
                {
                    DirectoryInfo[] DirList = di.GetDirectories();

                    checkedListBox1.BeginUpdate();
                    for (int i = 0; i < DirList.Length; i++)
                    {
                        checkedListBox1.Items.Add(DirList[i].Name);
                    }
                    checkedListBox1.EndUpdate();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The block directory loading process failed: {0}", e.ToString());
            }
            finally { }

            di = null;
        }

        private void Form_Closing(object sender, FormClosingEventArgs e)
        {
            this.Owner.Show();
        }
    }
}
